package com.project.light.controller;


import com.project.light.dto.*;
import com.project.light.entity.*;
import com.project.light.service.*;
import com.project.light.util.HttpUtil;
import com.project.light.util.RestResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/lighting-rest/api/v1/data/")
public class DataController {

    @Resource
    StationInfoService stationInfoService;
    @Resource
    GroupService groupService;
    @Resource
    StationStatusService stationStatusService;
    @Resource
    StationLightingPlanService stationLightingPlanService;
    @Resource
    GroupInfoService groupInfoService;
    @Resource
    DataService dataService;
    @Resource
    GroupPlanService groupPlanService;
    @Resource
    ConfigDto configDto;

    @PostMapping("StationInfo")
    public RestResult stationInfo(@RequestBody DataStationInfoParam param) {
        if (StringUtils.isEmpty(param.getSysId())) {
            return RestResult.error("sysId为空");
        }
        if (StringUtils.isEmpty(param.getSysname())) {
            return RestResult.error("sysname为空");
        }
        if (param.getOperateMode() == null) {
            return RestResult.error("operateMode为空");
        }
        if (!(param.getOperateMode() == 1 || param.getOperateMode() == 2 || param.getOperateMode() == 3)) {
            return RestResult.error("operateMode不正确");
        }
        if (StringUtils.isEmpty(param.getOperateTime())) {
            return RestResult.error("operateTime为空");
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date operateTime;
        try {
            operateTime = df.parse(param.getOperateTime());
        } catch (ParseException e) {
            return RestResult.error("operateTime格式不正确");
        }
        if (param.getStationInfoList() == null || param.getStationInfoList().size() == 0) {
            return RestResult.error("StationInfoList为空");
        }
        for (int i = 0; i < param.getStationInfoList().size(); i++) {
            if (param.getStationInfoList().get(i).getDistrictId() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,districtId为空");
            }
            if (param.getStationInfoList().get(i).getStationId() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,stationId为空");
            }
            if (StringUtils.isEmpty(param.getStationInfoList().get(i).getStationName())) {
                return RestResult.error("第" + (i + 1) + "条数据,stationName为空");
            }
            if (StringUtils.isEmpty(param.getStationInfoList().get(i).getAddress())) {
                return RestResult.error("第" + (i + 1) + "条数据,address为空");
            }
            if (StringUtils.isEmpty(param.getStationInfoList().get(i).getLongitude())) {
                return RestResult.error("第" + (i + 1) + "条数据,longitude为空");
            }
            if (StringUtils.isEmpty(param.getStationInfoList().get(i).getLatitude())) {
                return RestResult.error("第" + (i + 1) + "条数据,latitude为空");
            }
            if (param.getStationInfoList().get(i).getCircuitNum() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,circuitNum为空");
            }
            if (param.getStationInfoList().get(i).getDMXNum() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,DMXNum为空");
            }
            if (param.getStationInfoList().get(i).getEnergyMeter() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,energyMeter为空");
            }
            StationInfoR stationInfo = stationInfoService.getByIdR(param.getStationInfoList().get(i).getStationId(), param.getSysId());
            if (param.getOperateMode() == 1) {
                // 新增
                if (stationInfo != null && stationInfo.getDeleteFlag() == 0) {
                    return RestResult.error("stationId=" + param.getStationInfoList().get(i).getStationId() + "已存在,无法增加");
                }
                if (stationInfo == null) {
                    stationInfo = new StationInfoR();
                    stationInfo.setSysId(param.getSysId());
                    stationInfo.setSysName(param.getSysname());
                    stationInfo.setUpdateTime(operateTime);
                    stationInfo.setCreatedDate(operateTime);
                    stationInfo.setUpdatedDate(operateTime);
                    stationInfo.setCreatedUser(param.getSysId());
                    stationInfo.setUpdatedUser(param.getSysId());
                    stationInfo.setDistrictID(param.getStationInfoList().get(i).getDistrictId());
                    stationInfo.setStationName(param.getStationInfoList().get(i).getStationName());
                    stationInfo.setAddress(param.getStationInfoList().get(i).getAddress());
                    stationInfo.setLng(param.getStationInfoList().get(i).getLongitude());
                    stationInfo.setLat(param.getStationInfoList().get(i).getLatitude());
                    stationInfo.setCircuitNum(param.getStationInfoList().get(i).getCircuitNum());
                    stationInfo.setDmxNum(param.getStationInfoList().get(i).getDMXNum());
                    stationInfo.setEnergyMeter(param.getStationInfoList().get(i).getEnergyMeter());
                    stationInfo.setDeleteFlag(0);
                    stationInfo.setState(1);
                    stationInfo.setStationId(param.getStationInfoList().get(i).getStationId());
                    try {
                        if (param.getStationInfoList().get(i).getGroupId() != null) {
                            GroupInfo group = groupInfoService.getByGroupId(param.getStationInfoList().get(i).getGroupId(), param.getSysId());
                            if (group == null) {
                                return RestResult.error("groupId=" + param.getStationInfoList().get(i).getGroupId() + "不存在,无法增加");
                            }
                            stationInfo.setGroupID(param.getStationInfoList().get(i).getGroupId());
                        }
                        stationInfoService.insertR(stationInfo);
                    } catch (Exception e) {
                        return RestResult.error(e.getMessage());
                    }
                } else if (stationInfo.getDeleteFlag() == 1) {
                    stationInfo.setSysId(param.getSysId());
                    stationInfo.setSysName(param.getSysname());
                    stationInfo.setUpdateTime(operateTime);
                    stationInfo.setCreatedDate(operateTime);
                    stationInfo.setUpdatedDate(operateTime);
                    stationInfo.setCreatedUser(param.getSysId());
                    stationInfo.setUpdatedUser(param.getSysId());
                    stationInfo.setDistrictID(param.getStationInfoList().get(i).getDistrictId());
                    stationInfo.setStationName(param.getStationInfoList().get(i).getStationName());
                    stationInfo.setAddress(param.getStationInfoList().get(i).getAddress());
                    stationInfo.setLng(param.getStationInfoList().get(i).getLongitude());
                    stationInfo.setLat(param.getStationInfoList().get(i).getLatitude());
                    stationInfo.setCircuitNum(param.getStationInfoList().get(i).getCircuitNum());
                    stationInfo.setDmxNum(param.getStationInfoList().get(i).getDMXNum());
                    stationInfo.setEnergyMeter(param.getStationInfoList().get(i).getEnergyMeter());
                    stationInfo.setDeleteFlag(0);
                    stationInfo.setState(1);
                    stationInfo.setStationId(param.getStationInfoList().get(i).getStationId());
                    try {
                        if (param.getStationInfoList().get(i).getGroupId() != null) {
                            GroupInfo group = groupInfoService.getByGroupId(param.getStationInfoList().get(i).getGroupId(), param.getSysId());
                            if (group == null) {
                                return RestResult.error("groupId=" + param.getStationInfoList().get(i).getGroupId() + "不存在,无法增加");
                            }
                            stationInfo.setGroupID(param.getStationInfoList().get(i).getGroupId());
                        }
                        stationInfoService.updateR(stationInfo);
                    } catch (Exception e) {
                        return RestResult.error(e.getMessage());
                    }
                }
            } else if (param.getOperateMode() == 2) {
                // 更新
                if (stationInfo == null) {
                    return RestResult.error("stationId=" + param.getStationInfoList().get(i).getStationId() + "不存在,无法更新");
                }
                if (stationInfo.getDeleteFlag() == 1) {
                    return RestResult.error("stationId=" + param.getStationInfoList().get(i).getStationId() + "不存在,无法更新");
                }
                stationInfo.setSysId(param.getSysId());
                stationInfo.setSysName(param.getSysname());
                stationInfo.setUpdateTime(operateTime);
                stationInfo.setUpdatedDate(operateTime);
                stationInfo.setUpdatedUser(param.getSysId());
                stationInfo.setDistrictID(param.getStationInfoList().get(i).getDistrictId());
                stationInfo.setStationName(param.getStationInfoList().get(i).getStationName());
                stationInfo.setAddress(param.getStationInfoList().get(i).getAddress());
                stationInfo.setLng(param.getStationInfoList().get(i).getLongitude());
                stationInfo.setLat(param.getStationInfoList().get(i).getLatitude());
                stationInfo.setCircuitNum(param.getStationInfoList().get(i).getCircuitNum());
                stationInfo.setDmxNum(param.getStationInfoList().get(i).getDMXNum());
                stationInfo.setEnergyMeter(param.getStationInfoList().get(i).getEnergyMeter());
                stationInfo.setStationId(param.getStationInfoList().get(i).getStationId());
                stationInfo.setDeleteFlag(0);
                stationInfo.setState(1);
                try {
                    if (param.getStationInfoList().get(i).getGroupId() != null) {
                        GroupInfo group = groupInfoService.getByGroupId(param.getStationInfoList().get(i).getGroupId(), param.getSysId());
                        if (group == null) {
                            return RestResult.error("groupId=" + param.getStationInfoList().get(i).getGroupId() + "不存在,无法更新");
                        }
                        stationInfo.setGroupID(param.getStationInfoList().get(i).getGroupId());
                    } else {
                        stationInfo.setGroupID(null);
                    }
                    stationInfoService.updateR(stationInfo);
                } catch (Exception e) {
                    return RestResult.error(e.getMessage());
                }
            } else if (param.getOperateMode() == 3) {
                // 删除
                if (stationInfo == null) {
                    return RestResult.error("stationId=" + param.getStationInfoList().get(i).getStationId() + "不存在,无法删除");
                }
                stationInfo.setSysId(param.getSysId());
                stationInfo.setSysName(param.getSysname());
                stationInfo.setUpdateTime(operateTime);
                stationInfo.setUpdatedDate(operateTime);
                stationInfo.setUpdatedUser(param.getSysId());
                stationInfo.setDistrictID(param.getStationInfoList().get(i).getDistrictId());
                stationInfo.setStationName(param.getStationInfoList().get(i).getStationName());
                stationInfo.setAddress(param.getStationInfoList().get(i).getAddress());
                stationInfo.setLng(param.getStationInfoList().get(i).getLongitude());
                stationInfo.setLat(param.getStationInfoList().get(i).getLatitude());
                stationInfo.setCircuitNum(param.getStationInfoList().get(i).getCircuitNum());
                stationInfo.setDmxNum(param.getStationInfoList().get(i).getDMXNum());
                stationInfo.setEnergyMeter(param.getStationInfoList().get(i).getEnergyMeter());
                stationInfo.setStationId(param.getStationInfoList().get(i).getStationId());
                stationInfo.setDeleteFlag(1);
                stationInfo.setState(0);
                try {
                    stationInfoService.updateR(stationInfo);
                } catch (Exception e) {
                    return RestResult.error(e.getMessage());
                }
            }
        }
        return RestResult.ok();
    }

    @PostMapping("StationStatus")
    public RestResult stationStatus(@RequestBody DataStationStatusParam param) {
        if (StringUtils.isEmpty(param.getSysId())) {
            return RestResult.error("sysId为空");
        }
        if (StringUtils.isEmpty(param.getSysname())) {
            return RestResult.error("sysname为空");
        }
        if (StringUtils.isEmpty(param.getUpdateTime())) {
            return RestResult.error("updateTime为空");
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date updateTime;
        try {
            updateTime = df.parse(param.getUpdateTime());
        } catch (ParseException e) {
            return RestResult.error("updateTime格式不正确");
        }
        if (param.getStationStatusList() == null || param.getStationStatusList().size() == 0) {
            return RestResult.error("StationStatusList为空");
        }
        for (int i = 0; i < param.getStationStatusList().size(); i++) {
            if (param.getStationStatusList().get(i).getDistrictId() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,districtId为空");
            }
            if (param.getStationStatusList().get(i).getStationId() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,stationId为空");
            }
            if (StringUtils.isEmpty(param.getStationStatusList().get(i).getStationName())) {
                return RestResult.error("第" + (i + 1) + "条数据,stationName为空");
            }
            if (param.getStationStatusList().get(i).getCurrentPhaseA() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,currentPhaseA为空");
            }
            if (param.getStationStatusList().get(i).getCurrentPhaseB() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,currentPhaseB为空");
            }
            if (param.getStationStatusList().get(i).getCurrentPhaseC() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,currentPhaseC为空");
            }
            if (param.getStationStatusList().get(i).getVoltagePhaseA() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,voltagePhaseA为空");
            }
            if (param.getStationStatusList().get(i).getVoltagePhaseB() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,voltagePhaseB为空");
            }
            if (param.getStationStatusList().get(i).getVoltagePhaseC() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,voltagePhaseC为空");
            }
            if (param.getStationStatusList().get(i).getActivePower() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,activePower为空");
            }
            if (param.getStationStatusList().get(i).getElecConsumption() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,elecConsumption为空");
            }
            if (param.getStationStatusList().get(i).getGroupId() != null) {
                GroupInfo group = groupInfoService.getByGroupId(param.getStationStatusList().get(i).getGroupId(), param.getSysId());
                if (group == null) {
                    return RestResult.error("groupId=" + param.getStationStatusList().get(i).getGroupId() + "不存在,无法增加");
                }
            }
            StationStatus stationStatus = new StationStatus();
            stationStatus.setSysId(param.getSysId());
            stationStatus.setSysName(param.getSysname());
            stationStatus.setUpdateTime(updateTime);
            stationStatus.setDistrictID(param.getStationStatusList().get(i).getDistrictId());
            stationStatus.setStationID(param.getStationStatusList().get(i).getStationId());
            stationStatus.setStationName(param.getStationStatusList().get(i).getStationName());
            if (param.getStationStatusList().get(i).getGroupId() != null) {
                stationStatus.setGroupID(param.getStationStatusList().get(i).getGroupId());
            }
            if (param.getStationStatusList().get(i).getInputDis() != null) {
                stationStatus.setInputDis(String.join(",", param.getStationStatusList().get(i).getInputDis()));
            }
            stationStatus.setCurrentPhaseA(param.getStationStatusList().get(i).getCurrentPhaseA());
            stationStatus.setCurrentPhaseB(param.getStationStatusList().get(i).getCurrentPhaseB());
            stationStatus.setCurrentPhaseC(param.getStationStatusList().get(i).getCurrentPhaseC());
            stationStatus.setVoltagePhaseA(param.getStationStatusList().get(i).getVoltagePhaseA());
            stationStatus.setVoltagePhaseB(param.getStationStatusList().get(i).getVoltagePhaseB());
            stationStatus.setVoltagePhaseC(param.getStationStatusList().get(i).getVoltagePhaseC());
            stationStatus.setActivePower(param.getStationStatusList().get(i).getActivePower());
            stationStatus.setElecConsumption(param.getStationStatusList().get(i).getElecConsumption());
            try {
                stationStatusService.insert(stationStatus);
            } catch (Exception e) {
                return RestResult.error(e.getMessage());
            }
        }

        return RestResult.ok();
    }

    @PostMapping("StationLightingPlan")
    public RestResult stationLightingPlan(@RequestBody DataStationLightingPlanParam param) {
        if (StringUtils.isEmpty(param.getSysId())) {
            return RestResult.error("sysId为空");
        }
        if (StringUtils.isEmpty(param.getSysname())) {
            return RestResult.error("sysname为空");
        }
        if (StringUtils.isEmpty(param.getUpdateTime())) {
            return RestResult.error("updateTime为空");
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date updateTime;
        try {
            updateTime = df.parse(param.getUpdateTime());
        } catch (ParseException e) {
            return RestResult.error("updateTime格式不正确");
        }
        if (param.getLightingPlanList() == null || param.getLightingPlanList().size() == 0) {
            return RestResult.error("LightingPlanList为空");
        }
        for (int i = 0; i < param.getLightingPlanList().size(); i++) {
            if (param.getLightingPlanList().get(i).getDistrictId() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,districtId为空");
            }
            if (param.getLightingPlanList().get(i).getStationId() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,stationId为空");
            }
            if (StringUtils.isEmpty(param.getLightingPlanList().get(i).getStationName())) {
                return RestResult.error("第" + (i + 1) + "条数据,stationName为空");
            }
            if (param.getLightingPlanList().get(i).getGroupId() != null) {
                GroupInfo group = groupInfoService.getByGroupId(param.getLightingPlanList().get(i).getGroupId(), param.getSysId());
                if (group == null) {
                    return RestResult.error("groupId=" + param.getLightingPlanList().get(i).getGroupId() + "不存在,无法增加");
                }
            }
            StationLightingPlan stationLightingPlan = new StationLightingPlan();
            stationLightingPlan.setSysId(param.getSysId());
            stationLightingPlan.setSysName(param.getSysname());
            stationLightingPlan.setUpdateTime(updateTime);
            stationLightingPlan.setDistrictID(param.getLightingPlanList().get(i).getDistrictId());
            stationLightingPlan.setStationID(param.getLightingPlanList().get(i).getStationId());
            stationLightingPlan.setStationName(param.getLightingPlanList().get(i).getStationName());
            if (param.getLightingPlanList().get(i).getGroupId() != null) {
                stationLightingPlan.setGroupID(param.getLightingPlanList().get(i).getGroupId());
            }
            if (!StringUtils.isEmpty(param.getLightingPlanList().get(i).getTrunonTime())) {
                stationLightingPlan.setTrunonTime(param.getLightingPlanList().get(i).getTrunonTime());
            }
            if (!StringUtils.isEmpty(param.getLightingPlanList().get(i).getTurnoffTime())) {
                stationLightingPlan.setTurnoffTime(param.getLightingPlanList().get(i).getTurnoffTime());
            }
            if (param.getLightingPlanList().get(i).getLightingMode() != null) {
                stationLightingPlan.setLightingMode(param.getLightingPlanList().get(i).getLightingMode());
            }
            try {
                stationLightingPlanService.insert(stationLightingPlan);
            } catch (Exception e) {
                return RestResult.error(e.getMessage());
            }
        }
        return RestResult.ok();
    }

    @PostMapping("GroupInfo")
    public RestResult groupInfo(@RequestBody DataGroupInfoParam param) {
        if (StringUtils.isEmpty(param.getSysId())) {
            return RestResult.error("sysId为空");
        }
        if (StringUtils.isEmpty(param.getSysname())) {
            return RestResult.error("sysname为空");
        }
        if (StringUtils.isEmpty(param.getUpdateTime())) {
            return RestResult.error("updateTime为空");
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date updateTime;
        try {
            updateTime = df.parse(param.getUpdateTime());
        } catch (ParseException e) {
            return RestResult.error("updateTime格式不正确");
        }
        if (param.getGroupInfoList() == null || param.getGroupInfoList().size() == 0) {
            return RestResult.error("GroupInfoList为空");
        }
        for (int i = 0; i < param.getGroupInfoList().size(); i++) {
            if (param.getGroupInfoList().get(i).getDistrictId() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,districtId为空");
            }
            if (param.getGroupInfoList().get(i).getGroupId() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,groupId为空");
            }
            if (StringUtils.isEmpty(param.getGroupInfoList().get(i).getGroupName())) {
                return RestResult.error("第" + (i + 1) + "条数据,groupName为空");
            }
            if (param.getGroupInfoList().get(i).getStationNum() == null) {
                return RestResult.error("第" + (i + 1) + "条数据,stationNum为空");
            }
            GroupInfo groupInfo = groupInfoService.getByGroupId(param.getGroupInfoList().get(i).getGroupId(), param.getSysId());
            if (groupInfo != null) {
                groupInfo.setSysId(param.getSysId());
                groupInfo.setSysName(param.getSysname());
                groupInfo.setUpdateTime(updateTime);
                groupInfo.setDistrictID(param.getGroupInfoList().get(i).getDistrictId());
                groupInfo.setGroupName(param.getGroupInfoList().get(i).getGroupName());
                groupInfo.setStationNum(param.getGroupInfoList().get(i).getStationNum());
                if (param.getGroupInfoList().get(i).getStationIdList() != null) {
                    List<String> ids = new ArrayList<String>();
                    for (int n = 0; n < param.getGroupInfoList().get(i).getStationIdList().length; n++) {
                        ids.add(String.valueOf(param.getGroupInfoList().get(i).getStationIdList()[n]));
                    }
                    groupInfo.setStationIdList(String.join(",", ids));
                }
                try {
                    groupInfoService.update(groupInfo);
                } catch (Exception e) {
                    return RestResult.error(e.getMessage());
                }
            } else {
                groupInfo = new GroupInfo();
                groupInfo.setSysId(param.getSysId());
                groupInfo.setSysName(param.getSysname());
                groupInfo.setUpdateTime(updateTime);
                groupInfo.setDistrictID(param.getGroupInfoList().get(i).getDistrictId());
                groupInfo.setGroupID(param.getGroupInfoList().get(i).getGroupId());
                groupInfo.setGroupName(param.getGroupInfoList().get(i).getGroupName());
                groupInfo.setStationNum(param.getGroupInfoList().get(i).getStationNum());
                if (param.getGroupInfoList().get(i).getStationIdList() != null) {
                    List<String> ids = new ArrayList<String>();
                    for (int n = 0; n < param.getGroupInfoList().get(i).getStationIdList().length; n++) {
                        ids.add(String.valueOf(param.getGroupInfoList().get(i).getStationIdList()[n]));
                    }
                    groupInfo.setStationIdList(String.join(",", ids));
                }
                try {
                    groupInfoService.insert(groupInfo);
                } catch (Exception e) {
                    return RestResult.error(e.getMessage());
                }
            }
        }
        return RestResult.ok();
    }

    @PostMapping("login/post")
    public RestResult loginPost() {
        LoginPostParam loginPostParam = new LoginPostParam();
        loginPostParam.setPassword(configDto.getPassword());
        loginPostParam.setUsername(configDto.getUsername());
        loginPostParam.setVerifyCode(configDto.getVerifyCode());
        loginPostParam.setVerifyCodekey(configDto.getVerifyCodekey());
        LoginPost loginPost = new LoginPost();
        loginPost.setFunName(configDto.getFunName());
        loginPost.setServiceName(configDto.getServiceName());
        loginPost.setParam(loginPostParam);
        LoginPostResult result;
        try {
            String url = configDto.getPostHost() + "/api/service";
            HttpUtil httpUtil = new HttpUtil(url, configDto.getTimeout());
            result = httpUtil.loginPostUrl(loginPost);
        } catch (Exception e) {
            return RestResult.error(e.getMessage());
        }
        return RestResult.ok(result);
    }

    @PostMapping("stationInfo/post")
    public RestResult stationInfoPost(@RequestHeader(value = "authorization") String token, @RequestBody DateParam param) {
        List<DataStationInfoParam> sysList = stationInfoService.getSysList(param);
        for (DataStationInfoParam dataStationInfoParam : sysList) {
            param.setId(dataStationInfoParam.getSysId());
            List<DataStationInfo> dataList = stationInfoService.getStationList(param);
            dataStationInfoParam.setStationInfoList(dataList);
            try {
                String url = configDto.getPostHost() + "/lighting-rest/api/v1/data/StationInfo";
                HttpUtil httpUtil = new HttpUtil(url, configDto.getTimeout());
                httpUtil.postUrl2(dataStationInfoParam, token);
            } catch (Exception e) {
                return RestResult.error(e.getMessage());
            }
        }
        return RestResult.ok();
    }

    @PostMapping("group/post")
    public RestResult groupPost(@RequestHeader(value = "authorization") String token, @RequestBody DateParam param) {
        List<DataGroupInfoParam> sysList = groupService.getSysList(param);
        for (DataGroupInfoParam dataGroupInfoParam : sysList) {
            param.setId(dataGroupInfoParam.getSysId());
            List<DataGroupInfo> dataList = groupService.getGroupList(param);
            for (DataGroupInfo dataGroupInfo : dataList) {
                param.setGroupId(dataGroupInfo.getGroupId());
                List<DataStationInfo> idList = stationInfoService.getIdList(param);
                dataGroupInfo.setStationNum(idList.size());
                if (idList.size() > 0) {
                    dataGroupInfo.setStationIdList(idList.stream().map(DataStationInfo::getStationId).toArray(Integer[]::new));
                }
            }
            dataGroupInfoParam.setGroupInfoList(dataList);
            try {
                String url = configDto.getPostHost() + "/lighting-rest/api/v1/data/GroupInfo";
                HttpUtil httpUtil = new HttpUtil(url, configDto.getTimeout());
                httpUtil.postUrl2(dataGroupInfoParam, token);
            } catch (Exception e) {
                return RestResult.error(e.getMessage());
            }
        }
        return RestResult.ok();
    }

    @PostMapping("stationStatus/post")
    public RestResult stationStatusPost(@RequestHeader(value = "authorization") String token, @RequestBody DateParam param) {
        List<DataStationStatusParam> sysList = dataService.getSysList(param);
        for (DataStationStatusParam dataStationStatusParam : sysList) {
            param.setId(dataStationStatusParam.getSysId());
            List<DataStationStatus> dataList = dataService.getDataList(param);
            dataStationStatusParam.setStationStatusList(dataList);
            try {
                String url = configDto.getPostHost() + "/lighting-rest/api/v1/data/StationStatus";
                HttpUtil httpUtil = new HttpUtil(url, configDto.getTimeout());
                httpUtil.postUrl2(dataStationStatusParam, token);
            } catch (Exception e) {
                return RestResult.error(e.getMessage());
            }
        }
        return RestResult.ok();
    }

    @PostMapping("stationLightingPlan/post")
    public RestResult stationLightingPlanPost(@RequestHeader(value = "authorization") String token, @RequestBody DateParam param) {
        List<DataStationLightingPlanParam> sysList = groupPlanService.getSysList(param);
        for (DataStationLightingPlanParam dataStationLightingPlanParam : sysList) {
            param.setId(dataStationLightingPlanParam.getSysId());
            List<DataStationLightingPlanStatus> dataList = groupPlanService.getPlanList(param);
            dataStationLightingPlanParam.setLightingPlanList(dataList);
            try {
                String url = configDto.getPostHost() + "/lighting-rest/api/v1/data/StationLightingPlan";
                HttpUtil httpUtil = new HttpUtil(url, configDto.getTimeout());
                httpUtil.postUrl2(dataStationLightingPlanParam, token);
            } catch (Exception e) {
                return RestResult.error(e.getMessage());
            }
        }
        return RestResult.ok();
    }
}
